package ex4.gui;

import java.util.Collections;

import javax.swing.JFrame;

import ex4.logic.Configuration;
import ex4.logic.Score;

public class HighScoreScreen extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private javax.swing.JButton jButton1;
	private javax.swing.JList jList1;
	private javax.swing.JScrollPane jScrollPane1;

	public HighScoreScreen(){

		
		jButton1 = new javax.swing.JButton();
		jScrollPane1 = new javax.swing.JScrollPane();
		jList1 = new javax.swing.JList();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jButton1.setText("O.k");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				okButtonPressed(evt);
			}
		});
		


		jList1.setModel(new javax.swing.AbstractListModel() {			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			String[] strings ={};
			public int getSize() { return strings.length; }
			public Object getElementAt(int i) { return strings[i]; }
		});
		
		//sorting and adding the scores that should show
		Collections.sort(Configuration._scores);		
		Configuration._scores.toArray();
		String[] strings=new String[Configuration._scores.size()] ;
		int i=0;
        for (Score score : Configuration._scores) {
        	strings[i]= "Place Number " + (i+1) + " " + score.toString();
	        i++;
        }
        
        jList1.setListData(strings);
		
		jScrollPane1.setViewportView(jList1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addGap(60, 60, 60)
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
						.addComponent(jButton1)
						.addGap(37, 37, 37))
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
								.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
								.addComponent(jButton1))
								.addGap(26, 26, 26))
		);

	}

	private void okButtonPressed(java.awt.event.ActionEvent evt) {
		SnakeGameFirstScreen tGame=new SnakeGameFirstScreen();
		this.dispose();
		tGame.setVisible(true);
		//TODO
	}


}
